package org.wangchaocheng.cloudgallery.user.assembler;

import java.util.List;
import java.util.stream.Collectors;

import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.wangchaocheng.cloudgallery.commond.user.UserRoleSaveCmd;
import org.wangchaocheng.cloudgallery.dto.user.UserRoleDTO;

/**
 * 角色信息装配器
 *
 * @author wangchaocheng
 * @date 2025/03/28
 */
@Mapper
public interface UserRoleAssembler {

    UserRoleAssembler INSTANCE = Mappers.getMapper(UserRoleAssembler.class);

    default List<UserRoleDTO> assembleList(UserRoleSaveCmd userRoleSaveCmd) {
        return assembleList(userRoleSaveCmd.getUserId(), userRoleSaveCmd.getRoleIds());
    }

    default List<UserRoleDTO> assembleList(Long userId, List<Long> roleIdList) {
        return roleIdList.stream()
            .map(item -> {
                UserRoleDTO userRoleDTO = new UserRoleDTO();
                userRoleDTO.setUserId(userId);
                userRoleDTO.setRoleId(item);
                return userRoleDTO;
            }).collect(Collectors.toList());
    }

}
